﻿using System.Windows;
using System.Windows.Input;
using System.Windows.Interactivity;
using System.Windows.Media;

namespace nRoute.Samples.FutureDesktop.Behaviors
{
    public abstract class HoverBehaviorBase<T>
        : Behavior<T>
        where
            T : UIElement
    {
        public static readonly DependencyProperty HoverForegroundProperty = DependencyProperty.Register(
           "HoverForeground",
           typeof(Brush),
           typeof(HoverBehaviorBase<T>),
           new PropertyMetadata(null));

        public static readonly DependencyProperty HoverBackgroundProperty = DependencyProperty.Register(
            "HoverBackground",
            typeof(Brush),
            typeof(HoverBehaviorBase<T>),
            new PropertyMetadata(null));

        public static readonly DependencyProperty HoverBorderProperty = DependencyProperty.Register(
            "HoverBorder",
            typeof(Brush),
            typeof(HoverBehaviorBase<T>),
            new PropertyMetadata(null));
        
#region Override

        protected override void OnAttached()
        {
            base.OnAttached();
            this.AssociatedObject.MouseEnter += new MouseEventHandler(AssociatedObject_MouseEnter);
            this.AssociatedObject.MouseLeave += new MouseEventHandler(AssociatedObject_MouseLeave);
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();
            this.AssociatedObject.MouseEnter -= new MouseEventHandler(AssociatedObject_MouseEnter);
            this.AssociatedObject.MouseLeave -= new MouseEventHandler(AssociatedObject_MouseLeave);
        }

#endregion

#region Highlight Related

        protected abstract void OnHighlight();

        protected abstract void OnUnHighlight();

#endregion

#region Handlers

        private void AssociatedObject_MouseEnter(object sender, MouseEventArgs e)
        {
            OnHighlight();
        }

        private void AssociatedObject_MouseLeave(object sender, MouseEventArgs e)
        {
            OnUnHighlight();
        }

#endregion

    }
}
